import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * 服务器管理
 * @date: 2019-7-9


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function server() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/servers/clusters/cluster-id") : 'servers/clusters/cluster-id';
}

function canAssign() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/servers/can-assign") : 'servers/can-assign';
}

function serverAssign() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/server-assigns") : 'server-assigns';
}
/**
 * 根据clusterid查询带有cluster信息服务器信息
 * @param {Object} params - 参数
 */


export function fetchServerList(_x) {
  return _fetchServerList.apply(this, arguments);
}
/**
 * 查询可分配的服务器信息
 * @param {Object} params - 参数
 */

function _fetchServerList() {
  _fetchServerList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var clusterId;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            clusterId = params.clusterId;
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(server(), "/").concat(clusterId), {
              method: 'GET',
              query: params
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchServerList.apply(this, arguments);
}

export function fetchCanAssignList(_x2) {
  return _fetchCanAssignList.apply(this, arguments);
}
/**
 * 删除服务器集群分配信息
 * @param {Object} params - 参数
 */

function _fetchCanAssignList() {
  _fetchCanAssignList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var clusterId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            clusterId = params.clusterId;
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(canAssign(), "/").concat(clusterId), {
              method: 'GET',
              query: params
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchCanAssignList.apply(this, arguments);
}

export function deleteServerAssign(_x3) {
  return _deleteServerAssign.apply(this, arguments);
}
/**
 * 创建服务器集群分配信息
 * @param {Object} params - 参数
 */

function _deleteServerAssign() {
  _deleteServerAssign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(serverAssign()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _deleteServerAssign.apply(this, arguments);
}

export function createServerAssign(_x4) {
  return _createServerAssign.apply(this, arguments);
}

function _createServerAssign() {
  _createServerAssign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(serverAssign()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _createServerAssign.apply(this, arguments);
}